package opp.Abstract;

import java.util.Scanner;

public class Guess {
    public static void main(String[] args) {
        //猜数字游戏
        int num = 9;
        Scanner a = new Scanner(System.in );

        //让猜测次数为3次

        for (int i=1;i<=3;i++)
        {
            System.out.printf("请输入你的第%d次猜想：",i );
            if(a.hasNextInt() ){
                int n = a.nextInt() ;
                if(n==num){
                    System.out.println("\n恭喜你，猜对了！！！");
                    break;
                }else {
                    System.out.printf("\n你的第%d次猜想错误，你还剩下%d机会！\n",i,3-i);
                }
            }else {
                System.out.println("\n输入错误！请输入一个数字");
                a =new Scanner(System.in);

            }
        }
    }



    }

